
package com.ami.iusb;

import com.ami.kvm.jviewer.Debug;
import com.ami.kvm.jviewer.JViewer;
import com.ami.vmedia.VMApp;
import com.ami.vmedia.gui.DeviceControlPanel;
import com.ami.vmedia.gui.VMPane;

public class vHarddiskMonitorThread extends Thread {
	private HarddiskRedir harddiskRedir = null;
	private String[] harddiskList = null;
	private String[] harddiskFixedList = null;
	private String[] harddiskUSBList = null;
	private String harddiskSource = null;
	private boolean harddiskThreadStatus = false;
	private boolean isMediaMatched = false;
	private int hddevice_no = 0;

	public vHarddiskMonitorThread(int paramInt) {
		this.hddevice_no = paramInt;
	}

	public void startharddiskMonitor() {
		this.harddiskThreadStatus = true;
		start();
	}

	public void stopFloppyMonitor() {
		this.harddiskThreadStatus = false;
	}

	public void run() {
		this.harddiskRedir = new HarddiskRedir(true);
		this.harddiskSource = VMApp.getInstance().getIUSBRedirSession().getHarddiskSource(this.hddevice_no);
		String str = this.harddiskSource.substring(0, this.harddiskSource.lastIndexOf("-"));
		this.harddiskSource = str.trim();

		while (this.harddiskThreadStatus) {
			try {
				this.harddiskUSBList = this.harddiskRedir.getUSBHDDList();
				if ((true == JViewer.IsClientAdmin()) && ((JViewer.getOEMFeatureStatus() & 0x2) != 2L)) {
					this.harddiskFixedList = this.harddiskRedir.getHarddiskFixedList();
				}
				int i = 0;
				int j = 0;
				int k = 0;

				if (this.harddiskUSBList != null) {
					j = this.harddiskUSBList.length;
				}
				if (this.harddiskFixedList != null) {
					k = this.harddiskFixedList.length;
				}
				i = j + k;
				this.harddiskList = new String[i];

				for (int m = 0; m < j; m++) {
					if (this.harddiskUSBList[m] != null)
						this.harddiskList[m] = this.harddiskUSBList[m];
				}
				for (int m = 0; m < k; m++) {
					String[] arrayOfString = this.harddiskFixedList[m].split("-");
					if (arrayOfString != null) {
						this.harddiskList[(m + j)] = arrayOfString[0];
					}
				}
				if (!VMApp.getInstance().isHDRedirRunning(this.hddevice_no)) {
					break;
				}
				if (this.harddiskList == null) {
					VMApp.getInstance().getIUSBRedirSession().StopHarddiskImageRedir(this.hddevice_no, 3);
					VMApp.getVMPane().getDeviceControlPanel(2, this.hddevice_no).updateDeviceControlPanel();
				} else {
					for (int m = 0; m < this.harddiskList.length; m++) {

						if (this.harddiskSource.startsWith(this.harddiskList[m])) {
							this.isMediaMatched = true;
							break;
						}
					}

					if (!this.isMediaMatched) {
						Debug.out.println(
								"REDIRECTED Harddisk MEDIUM REMOVAL HAS BEEN DETECTED, STOPPING REDIRECTION TO PREVENT FURTHER DAMAGE");
						VMApp.getInstance().getIUSBRedirSession().StopHarddiskRedir(this.hddevice_no, 3);
						VMApp.getVMPane().getDeviceControlPanel(2, this.hddevice_no).updateDeviceControlPanel();
					} else {
						this.isMediaMatched = false;
					}
				}

				sleep(2000L);
			} catch (InterruptedException localInterruptedException) {
				stopHDAbnormal();
				Debug.out.println(localInterruptedException);
			} catch (Exception localException) {
				stopHDAbnormal();
				Debug.out.println(localException);
			}
		}
	}

	private void stopHDAbnormal() {
		VMApp.getInstance().getIUSBRedirSession().stopHarddiskAbnormal(this.hddevice_no);
	}
}

/*
 * Location:
 * D:\Users\tianlin\Downloads\JViewer.jar!\com\ami\iusb\vHarddiskMonitorThread.
 * class Java compiler version: 5 (49.0) JD-Core Version: 0.7.1
 */